﻿using System;
using System.Collections.Generic;

namespace Librarinth
{
	public class Register
	{
		public int Count { get; private set; }

		int lastIndex	= 0;
		readonly Queue<int> emptyIndex	= new Queue<int>();
		public void Alloc(out int index)
		{
			if(emptyIndex.Count < 1)
			{
				index	= lastIndex;
				lastIndex++;
			}
			else index	= emptyIndex.Dequeue();
			Count++;
		}

		public void Free(ref int index)
		{
			emptyIndex.Enqueue(index);
			index	= -1;
			Count--;
		}
	}

}
